package com.dragon.app.design.pattern.singleton;

/**
 * 
 * <p>class: Singleton2</p>  
 * <p>Description: 单例模式 普通懒汉式实现</p>  
 * @author SmallDragon
 * @date 2019年3月26日
 *
 */
public class Singleton2 {
	private static Singleton2 instance;

	private Singleton2() {
	}

	//非同步的，线程不安全
	public static Singleton2 getInstance1() {
		if (instance == null) {
			instance = new Singleton2();
		}
		return instance;
	}

	//同步的，线程安全，效率低
	public static synchronized Singleton2 getInstance() {
		if (instance == null) {
			instance = new Singleton2();
		}

		return instance;
	}

}
